package genedit.controller.interfaceActions;

import genedit.gui.GMainFrame;
import genedit.model.Package;
import genedit.model.Project;
import genedit.model.Workspace;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zadužena za kreiranje novog projekta.
 * 
 * @author Nikola
 * @version 1.0 5/11/13
 */
public class GNewProjectA extends AbstractAction {
	private static final long serialVersionUID = 1L;

	protected static GNewProjectA newD = null;

	protected GNewProjectA() {
		putValue(NAME, "New Project");
		putValue(SHORT_DESCRIPTION, "New Project");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/tproject.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_N);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control N"));
	}

	public static AbstractAction getInstance() {
		if (newD == null)
			newD = new GNewProjectA();
		return newD;
	}

	/**
	 * Akcija kreira novi projekat i daje mu podrazumevani naziv.
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		Project p = new Project(Workspace.getInstance(), GMainFrame.getInstance()
				.getResourceBundle().getString("Project"));
		p.addPackages(new Package(p, GMainFrame.getInstance().getResourceBundle()
				.getString("Package")
				+ " " + p.getElementCount()));
		Workspace.getInstance().addProjects(p);
	}
}